﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ThresholdModeling
{
    public class MemberInfo
    {
        private int _I;

        public int I
        {
            get { return _I; }
            set { _I = value; }
        }

        private int _mi;

        public int mi
        {
            get { return _mi; }
            set { _mi = value; }
        }

        private String _memberID;

        public String MemberID
        {
            get { return _memberID; }
            set { _memberID = value; }
        }

        private String _name;

        public String Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private String _role;

        public String Role
        {
            get { return _role; }
            set { _role = value; }
        }

        private String _email;

        public String Email
        {
            get { return _email; }
            set { _email = value; }
        }

        private MembersGroup _group;

        public MembersGroup Group
        {
            get { return _group; }
            set { _group = value; }
        }

        public MemberInfo()
        {
        }

        public MemberInfo(MemberInfo mem)
        {
            this._memberID = mem._memberID;
            this._name = mem._name;
            this._group = mem._group;
            this._role = mem._role;
            this._I = mem._I;
            this._mi = mem._mi;
            this._email = mem._email;
        }

        public MemberInfo(int mi, int I)
        {
            this._I = I;
            this._mi = mi;
        }

        public MemberInfo(int I, int mi, MembersGroup group)
        {
            this._I = I;
            this._mi = mi;
            this._group = group;
        }

        public MemberInfo(String id, String name, String email, String role)
        {
            this._memberID = id;
            this._name = name;
            this._email = email;
            this._role = role;

            this._I = 0;
            this._mi = 0;
        }

        public MemberInfo(String id, String name, String email, String role, MembersGroup group)
        {
            this._memberID = id;
            this._name = name;
            this._email = email;
            this._role = role;
            this._group = group;

            this._I = 0;
            this._mi = 0;
        }

        public void GetInfo(int I, int mi, BigInteger M, String secret)
        {
            this._I = I;
            this._mi = mi;
            MembersGroup oGroup = this._group;
            MembersGroup group = new MembersGroup(oGroup.GroupID, oGroup.GroupName, oGroup.Password, oGroup.NMembers, oGroup.KMembers,
                                                   M, secret);
            this._group = group;
        }

        public bool CheckValidInfo()
        {
            //Check valid role
            bool validRole = true;
            if (!"Key member".Equals(this._role) && !"key member".Equals(this._role) && !"Member".Equals(this._role)
                && !"member".Equals(this._role) && !"".Equals(this._role))
                validRole = false;

            //Check valid email
            bool validEmail = true;
            if (this._email == null)
                return false;
            bool c = this._email.Contains("@");
            if (!c)
                validEmail = false;
            else
            {
                if (_email.IndexOf('@') == _email.Length - 1)
                    validEmail = false;
            }

            return (validEmail && validRole);
        }

        public bool isAdmin()
        {
            if ("Key member".Equals(this._role) || "key member".Equals(this._role))
                return true;
            return false;
        }

    }
}
